//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
    public static void main(String[] args) {
        //1.BM2指定区间链表反转
        public ListNode reverseBetween (ListNode head, int m, int n) {
            if(head == null) {
                return null;
            }
            ListNode newhead = new ListNode(-1);
            newhead.next = head;
            ListNode prve = null;
            ListNode tmp = null;
            ListNode cur = newhead;
            ListNode p = null;
            ListNode q = null;
            for(int i = 0; i < m-1;i++) {
                cur = cur.next;
            }
            p = cur;
            q = p.next;
            cur = q;
            for(int i = m;i<=n;i++) {
                tmp = cur.next;
                cur.next = prve;
                prve = cur;
                cur = tmp;
            }
            q.next = tmp;
            p.next = prve;
            return newhead.next;
        }
        //2.BM12单链表排序
        public ListNode sortInList (ListNode head) {
            List<Integer> list = new ArrayList<>();
            ListNode cur = head;
            while(cur != null) {
                list.add(cur.val);
                cur = cur.next;
            }
            int[] array = new int[list.size()];
            for(int i = 0;i<list.size();i++) {
                array[i] = list.get(i);
            }
            Arrays.sort(array);
            ListNode newhead = new ListNode(-1);
            ListNode tmp = newhead;
            for(int value: array) {
                ListNode newNode = new ListNode(value);
                tmp.next = newNode;
                tmp = newNode;
            }
            return newhead.next;

        }
    }
}